﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Zocono.WCS.Domain.PlcBytesObject
{
    public class BytesObjectServiceFactory : IBytesObjectServiceFactory
    {
        //private readonly IServiceProvider _provider;
        private readonly IEnumerable<BytesObjectBase> _services;
        public BytesObjectServiceFactory(IEnumerable<BytesObjectBase> services)
        {
            _services = services;
        }
        public BytesObjectBase Create(string name)
        {
            //var type = Assembly.GetAssembly(typeof(BytesObjectServiceFactory)).GetType($"Zocono.WCS.Domain.PlcBytesObject.{name}");
            //var instance = _provider.GetService(type);
            //return instance as BytesObjectBase;

            //var instance = _services.SingleOrDefault(s => s.GetType().Name == name);
            //return instance;

            ////BytesObjectBase bytesObjectBase = null;
            ////switch (name)
            ////{
            ////    case "ZJNScMessagePlcActionBO":
            ////        bytesObjectBase = new ZJNScMessagePlcActionBO();
            ////        break;
            ////    case "ZJNScMessageWcsActionBO":
            ////        bytesObjectBase = new ZJNScMessageWcsActionBO();
            ////        break;
            ////    case "PlanarGeneralPlcActionBO":
            ////        bytesObjectBase = new PlanarGeneralPlcActionBO();
            ////        break;
            ////    case "PlanarGeneralWcsActionBO":
            ////        bytesObjectBase = new PlanarGeneralWcsActionBO();
            ////        break;
            ////    case "PlcOnLineStateBO":
            ////        bytesObjectBase = new PlcOnLineStateBO();
            ////        break;
            ////}
            ////return bytesObjectBase;

            var type = Assembly.GetAssembly(typeof(BytesObjectServiceFactory)).GetType($"Zocono.WCS.Domain.PlcBytesObject.{name}");
            BytesObjectBase bytesObjectBase = Activator.CreateInstance(type) as BytesObjectBase;
            return bytesObjectBase;
        }

    }
}
